{% extends 'blog/base.html' %}

{% block title %}
个人中心
{% endblock %}

{% block content %}
<div class="container">
    <div class="row justify-content-center">
        <div class="card mt-3 px-0 col-md-6">
            <div class="card-header text-center">
                个人资料
            </div>
            <div class="card-body">
                <form method="post" enctype="multipart/form-data">
                    {% csrf_token %}
                    {% for field in form %}
                    {% if field.name == 'avatar' %}
                    <div class="d-flex flex-column align-items-center">
                        <label for="{{ field.id_for_label }}" style="cursor: pointer;">
                            <img src="{{ field.value.url }}">
                        </label>
                        <small>点击头像更换图片</small>
                    </div>
                    {{ field }}
                    {% else %}
                    <div>
                        {{ field.label_tag }}
                        {{ field }}
                    </div>
                    {% endif %}

                    {% if field.errors %}
                    <div class="alert alert-danger mt-2">
                        {% for error in field.errors %}
                        {{ error }}
                        {% endfor %}
                    </div>
                    {% endif %}
                    {% endfor %}

                    <!-- 提交按钮 -->
                    <button class="btn btn-primary" type="submit">更新</button>
                    <a class="btn btn-secondary" href="#" onclick="history.back()">取消</a>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}